package database;

import java.sql.CallableStatement;

import object.TimeSheet;
import clientMain.Login;

public class TimeSheetDelegate {
	
	public boolean insertTs(TimeSheet ts, int userId){
		boolean flag = true;
		try {
			Login.conn.setAutoCommit(false);
			CallableStatement cst = Login.conn.prepareCall("{call sp_InsertTs(?,?,?,?,?,?)}");
			cst.setString(1, ts.getEmId());
			cst.setString(2, ts.getDate());
			cst.setBoolean(3, ts.isMor());
			cst.setBoolean(4, ts.isAft());
			cst.setBoolean(5, ts.isEve());
			cst.setInt(6, userId);
			cst.executeUpdate();
			Login.conn.commit();
		} catch (Exception e) {
			flag = false;
			e.printStackTrace();
		}
		return flag;
	} 
	
	public boolean updateTS(TimeSheet ts, int userId){
		boolean flag = true;
		try {
			Login.conn.setAutoCommit(false);
			CallableStatement cst = Login.conn.prepareCall("{call sp_UpdateTs(?,?,?,?,?,?)}");
			cst.setString(1, ts.getEmId());
			cst.setString(2, ts.getDate());
			cst.setBoolean(3, ts.isMor());
			cst.setBoolean(4, ts.isAft());
			cst.setBoolean(5, ts.isEve());
			cst.setInt(6, userId);
			cst.executeUpdate();
			Login.conn.commit();
		} catch (Exception e) {
			e.printStackTrace();
			flag = false;
		}
		return flag;
	}
}
